public class Scope
extends java.lang.Object
implements java.lang.Iterable<java.lang.Object>, java.lang.Cloneable
List and Map which allow you to have both variables and independent values managed by one Object. Map methods such as put(String key, Object) and array of independent values is accessed by via List methods such as add(Object) and get(int)Serializer and supposed to be read only!
{
//This is scope in SerialX!
}
| Constructor and Description |
|---|
Scope(java.util.Map<java.lang.String,java.lang.Object> variablesMap,
java.util.Collection<java.lang.Object> values) |
Scope(java.util.Map<java.lang.String,java.lang.Object> variablesMap,
java.lang.Object... values) |
Scope(java.lang.Object... values) |
| Modifier and Type | Method and Description |
|---|---|
Scope |
clone() |
boolean |
containsIndependentValue(java.lang.Object value) |
boolean |
containsVariable(java.lang.String variableName) |
<T> Scope |
filter(java.util.function.Predicate<T> predicate) |
<T> Scope |
filter(java.util.function.Predicate<T> predicate,
boolean includeSubScopes) |
<T> T |
get(int valueIndex) |
<T> T |
get(java.lang.String variableName) |
<T> T |
get(java.lang.String variableName,
T defaultValue) |
boolean |
getBool(int valueIndex) |
boolean |
getBool(java.lang.String variableName) |
boolean |
getBool(java.lang.String variableName,
boolean defaultValue) |
byte |
getByte(int valueIndex) |
byte |
getByte(java.lang.String variableName) |
byte |
getByte(java.lang.String variableName,
byte defaultValue) |
double |
getDouble(int valueIndex) |
double |
getDouble(java.lang.String variableName) |
double |
getDouble(java.lang.String variableName,
double defaultValue) |
float |
getFloat(int valueIndex) |
float |
getFloat(java.lang.String variableName) |
float |
getFloat(java.lang.String variableName,
float defaultValue) |
char |
getChar(int valueIndex) |
char |
getChar(java.lang.String variableName) |
char |
getChar(java.lang.String variableName,
char defaultValue) |
int |
getInt(int valueIndex) |
int |
getInt(java.lang.String variableName) |
int |
getInt(java.lang.String variableName,
int defaultValue) |
long |
getLong(int valueIndex) |
int |
getLong(java.lang.String variableName) |
long |
getLong(java.lang.String variableName,
long defaultValue) |
Scope |
getParent() |
Scope |
getScope(int scopesOrderIndex) |
Scope |
getScope(java.lang.String... scopesPath) |
Scope |
getScopeAt(int scopeValueIndex) |
short |
getShort(int valueIndex) |
short |
getShort(java.lang.String variableName) |
short |
getShort(java.lang.String variableName,
short defaultValue) |
java.lang.String |
getString(int valueIndex) |
java.lang.String |
getString(java.lang.String variableName) |
java.lang.String |
getString(java.lang.String variableName,
java.lang.String defaultValue) |
<T> T |
getVarAt(int index) |
<T> T |
getVarAt(int index,
T defaultValue) |
boolean |
isEmpty() |
java.util.Iterator<java.lang.Object> |
iterator() |
<T> T |
toObject(java.lang.Class<T> objClass) |
<T> T |
toObjectFrom(int scopesValueIndex,
java.lang.Class<T> objClass) |
<T> T |
toObjectFrom(java.lang.String variableWithScope,
java.lang.Class<T> objClass) |
<T> T |
toObjectFrom(java.lang.String variableWithScope,
java.lang.Class<T> objClass,
T defaultValue) |
java.lang.String |
toString() |
java.lang.Object[] |
toValArray() |
java.util.List<java.lang.Object> |
toValList() |
java.util.LinkedHashMap<java.lang.String,java.lang.Object> |
toVarMap() |
<T> Scope |
transform(java.util.function.Function<T,java.lang.Object> trans) |
<T> Scope |
transform(java.util.function.Function<T,java.lang.Object> trans,
boolean includeSubScopes) |
int |
valuesCount() |
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> |
varEntrySet() |
int |
variablesCount() |
@SafeVarargs public Scope(java.lang.Object... values)
values - | Initial independent values to be added in to this scope!@SafeVarargs
public Scope(java.util.Map<java.lang.String,java.lang.Object> variablesMap,
java.lang.Object... values)
variablesMap - | Initial variables to be added in to this scope!values - | Initial independent values to be added in to this scope!public Scope(java.util.Map<java.lang.String,java.lang.Object> variablesMap,
java.util.Collection<java.lang.Object> values)
variablesMap - | Initial variables to be added in to this scope!values - | Initial independent values to be added in to this scope!public java.lang.String toString()
toString in class java.lang.Objectpublic Scope clone()
clone in class java.lang.Objectpublic java.util.Iterator<java.lang.Object> iterator()
iterator in interface java.lang.Iterable<java.lang.Object>public byte getByte(java.lang.String variableName)
variableName - | Variables name.defaultValue - | Default value to return.Number, Character or CharSequence if possible!public byte getByte(java.lang.String variableName,
byte defaultValue)
variableName - | Variables name.defaultValue - | Default value to return.Number, Character or CharSequence if possible!public short getShort(java.lang.String variableName)
variableName - | Variables name.defaultValue - | Default value to return.Number, Character or CharSequence if possible!public short getShort(java.lang.String variableName,
short defaultValue)
variableName - | Variables name.defaultValue - | Default value to return.Number, Character or CharSequence if possible!public int getInt(java.lang.String variableName)
variableName - | Variables name.defaultValue - | Default value to return.Number, Character or CharSequence if possible!public int getInt(java.lang.String variableName,
int defaultValue)
variableName - | Variables name.defaultValue - | Default value to return.Number, Character or CharSequence if possible!public int getLong(java.lang.String variableName)
variableName - | Variables name.defaultValue - | Default value to return.Number, Character or CharSequence if possible!public long getLong(java.lang.String variableName,
long defaultValue)
variableName - | Variables name.defaultValue - | Default value to return.Number, Character or CharSequence if possible!public float getFloat(java.lang.String variableName)
variableName - | Variables name.defaultValue - | Default value to return.Number, Character or CharSequence if possible!public float getFloat(java.lang.String variableName,
float defaultValue)
variableName - | Variables name.defaultValue - | Default value to return.Number, Character or CharSequence if possible!public double getDouble(java.lang.String variableName)
variableName - | Variables name.defaultValue - | Default value to return.Number, Character or CharSequence if possible!public double getDouble(java.lang.String variableName,
double defaultValue)
variableName - | Variables name.defaultValue - | Default value to return.Number, Character or CharSequence if possible!public java.lang.String getString(java.lang.String variableName)
variableName - | Variables name.defaultValue - | Default value to return.Object.toString()!public java.lang.String getString(java.lang.String variableName,
java.lang.String defaultValue)
variableName - | Variables name.defaultValue - | Default value to return.Object.toString()!public char getChar(java.lang.String variableName)
variableName - | Variables name.defaultValue - | Default value to return.(char) 0 if there is no such a one!
Char will be also parsed from Number, Character or CharSequence if possible!public char getChar(java.lang.String variableName,
char defaultValue)
variableName - | Variables name.defaultValue - | Default value to return.Number, Character or CharSequence if possible!public boolean getBool(java.lang.String variableName)
variableName - | Variables name.Number, or CharSequence if possible!public boolean getBool(java.lang.String variableName,
boolean defaultValue)
variableName - | Variables name.defaultValue - | Default value to return.Number, or CharSequence if possible!public <T> T getVarAt(int index)
index - | Index of variable!public <T> T getVarAt(int index,
T defaultValue)
index - | Index of variable!defaultValue - | Default value to return.public <T> T get(java.lang.String variableName)
variableName - | Variables name.public <T> T get(java.lang.String variableName,
T defaultValue)
variableName - | Variables name.defaultValue - | Default value to return.public boolean containsVariable(java.lang.String variableName)
variableName - | Variables name to search for.public boolean containsIndependentValue(java.lang.Object value)
value - | Objecthe value.public byte getByte(int valueIndex)
valueIndex - | Index of independent value. Also can be negative, in this case u will get elements from back!
IndexOutOfBoundsException will be thrown if index is too big!Number, Character or CharSequence if possible!public short getShort(int valueIndex)
valueIndex - | Index of independent value. Also can be negative, in this case u will get elements from back!
IndexOutOfBoundsException will be thrown if index is too big!Number, Character or CharSequence if possible!public int getInt(int valueIndex)
valueIndex - | Index of independent value. Also can be negative, in this case u will get elements from back!
IndexOutOfBoundsException will be thrown if index is too big!Number, Character or CharSequence if possible!public long getLong(int valueIndex)
valueIndex - | Index of independent value. Also can be negative, in this case u will get elements from back!
IndexOutOfBoundsException will be thrown if index is too big!Number, Character or CharSequence if possible!public float getFloat(int valueIndex)
valueIndex - | Index of independent value. Also can be negative, in this case u will get elements from back!
IndexOutOfBoundsException will be thrown if index is too big!Number, Character or CharSequence if possible!public double getDouble(int valueIndex)
valueIndex - | Index of independent value. Also can be negative, in this case u will get elements from back!
IndexOutOfBoundsException will be thrown if index is too big!Number, Character or CharSequence if possible!public java.lang.String getString(int valueIndex)
valueIndex - | Index of independent value. Also can be negative, in this case u will get elements from back!
IndexOutOfBoundsException will be thrown if index is too big!Object.toString()!public char getChar(int valueIndex)
valueIndex - | Index of independent value. Also can be negative, in this case u will get elements from back!
IndexOutOfBoundsException will be thrown if index is too big!Number, Character or CharSequence if possible!public boolean getBool(int valueIndex)
valueIndex - | Index of independent value. Also can be negative, in this case u will get elements from back!
IndexOutOfBoundsException will be thrown if index is too big!Number, or CharSequence if possible!public <T> T get(int valueIndex)
valueIndex - | Index of independent value. Also can be negative, in this case u will get elements from back!
IndexOutOfBoundsException will be thrown if index is too big!public Scope getScopeAt(int scopeValueIndex)
scopeValueIndex - | Index of sub-scopes value.public Scope getScope(int scopesOrderIndex)
scopesOrderIndex - | Order index of sub-scope.getScopeAt(int) however this will ignore non scope variables.
variable = "something";
"something";
{
"Scope0"
};
123;
null;
{
"Scope1" <- This one will be returned!
};
4;
5;
6;
{
"Scope2"
}
public Scope getScope(java.lang.String... scopesPath)
scopesPath - | Array with variable names creating path to required scope.
variable = "something";
scope1 =
{
subScope =
{
scopeObjectoFind = {...}; <- this one will be returned if getScope("scope1", "scopeObjectoFind") is issued!
7;...
}
};
scopeObjectoFind = {...} <- this one will be returned if getScope("scopeObjectoFind") is issued!
Note: Remember that this search includes variables only, no values!public <T> T toObjectFrom(int scopesValueIndex,
java.lang.Class<T> objClass)
throws java.lang.Exception
scopesValueIndex - | Index of independent value. Also can be negative, in this case u will get elements from back!
IndexOutOfBoundsException will be thrown if index is too big!objClass - | Object of class to create.get(int)!
If independent value is Scope like it supposed to, then values of scope are parsed to SerializationProtocol of objClass.
Note: Scopes are searched via regular independent value index no scope index like getScope(int).java.lang.Exception - if Exception occurred in SerializationProtocol.unserialize(Class, Object...)!Serializer.PROTOCOL_REGISTRY,
toObject(Class)public <T> T toObjectFrom(java.lang.String variableWithScope,
java.lang.Class<T> objClass)
throws java.lang.Exception
variableWithScope - | Variable that supposed to contains scope.objClass - | Object of class to create.get(String, Object)!
If variableWithScope contains Scope like it supposed to, then values of scope are parsed to SerializationProtocol of objClass.java.lang.Exception - if Exception occurred in SerializationProtocol.unserialize(Class, Object...)!Serializer.PROTOCOL_REGISTRY,
toObject(Class)public <T> T toObjectFrom(java.lang.String variableWithScope,
java.lang.Class<T> objClass,
T defaultValue)
throws java.lang.Exception
variableWithScope - | Variable that supposed to contains scope.objClass - | Object of class to create.defaultValue - | Default value to return.get(String, Object)!
If variableWithScope contains Scope like it supposed to, then values of scope are parsed to SerializationProtocol of objClass.java.lang.Exception - if Exception occurred in SerializationProtocol.unserialize(Class, Object...)!Serializer.PROTOCOL_REGISTRY,
toObject(Class)public <T> T toObject(java.lang.Class<T> objClass)
throws java.lang.Exception
objClass - | Object of class to create.Serializer.PROTOCOL_REGISTRY!java.lang.Exception - | Exception if Exception occurred in SerializationProtocol.unserialize(Class, Object...)!public <T> Scope filter(java.util.function.Predicate<T> predicate)
predicate - | Predicate object with filter condition in test method!Predicate.test(Object) argument, it will be treated as invalid and will be filtered away! Sub-scopes are not included!public <T> Scope filter(java.util.function.Predicate<T> predicate, boolean includeSubScopes)
predicate - | Predicate object with filter condition in test method!includeSubScopes - | If true filtration will be also applied on sub-scopes, if false sub-scopes will be treated as other things (parsed in to Predicate.test(Object)).
If sub-scope is empty after filtration it will not be included in result!Predicate.test(Object) argument, it will be treated as invalid and will be filtered away!public <T> Scope transform(java.util.function.Function<T,java.lang.Object> trans)
trans - | Function to transform objects of this scope!Function.apply(Object) argument, it will be treated as invalid and will be filtered away! Sub-scopes are not included!public <T> Scope transform(java.util.function.Function<T,java.lang.Object> trans, boolean includeSubScopes)
trans - | Function to transform objects of this scope!includeSubScopes - | If true transformation will be also applied on sub-scopes, if false sub-scopes will be treated as other things (parsed in to Function.apply(Object)).
If sub-scope is empty after transformation it will not be included in result!Function.apply(Object) argument, it will be treated as invalid and will be filtered away!public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> varEntrySet()
public int valuesCount()
public int variablesCount()
public boolean isEmpty()
public Scope getParent()
public java.util.LinkedHashMap<java.lang.String,java.lang.Object> toVarMap()
LinkedHashMap with variables of this Scope in defined order! Key is a string name of variable and value is its value! public java.util.List<java.lang.Object> toValList()
ArrayList with independent values of this Scope. These values have nothing to do with values of variables, they are independent!
Modifying this list will not affect this Scope object!public java.lang.Object[] toValArray()